home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / developm / source / ncsat.cpt / Telnet2.5 final / main / event.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-05  |  38.4 KB  |  1,523 lines

  1. #ifdef lint
  2. static char *SCCSid = "%W%    (NCSA)    %G%";
  3. #endif
  4. /*
  5. *    event.c
  6. *     by Gaige B. Paulsen
  7. ****************************************************************************
  8. *    Part of NCSA Telnet for the Macintosh                                   *
  9. *                                                                          *
  10. *      Uses    :                                                               *
  11. *      TCP/IP kernel for NCSA Telnet                                       *
  12. *      by Tim Krauskopf                                                    *
  13. *       with Macintosh code by Gaige B. Paulsen                                 *
  14. *                                                                          *
  15. *      National Center for Supercomputing Applications                     *
  16. *      152 Computing Applications Building                                 *
  17. *      605 E. Springfield Ave.                                             *
  18. *      Champaign, IL  61820                                                *
  19. *                                                                          *
  20. *                                                                          *
  21. ****************************************************************************
  22. *
  23. *    Main Event loop code for NCSA Telnet for the Macintosh
  24. *
  25. *    Called by:
  26. *        maclook.c
  27. */
  28.  
  29. /*
  30.  *    Files for inclusion.
  31.  */
  32. #include    <stdio.h>
  33. #include    <ctype.h>
  34. #include <string.h>
  35.  
  36. #include    <Controls.h>
  37. #include    <Desk.h>
  38. #include    <Dialogs.h>
  39. #include <DiskInit.h>
  40. #include    <Events.h>
  41. #include    <Fonts.h>
  42. #include    <Menus.h>
  43. #include <Memory.h>
  44. #include <OSEvents.h>
  45. #include    <OSUtils.h>            /* for Juggler */
  46. #include    <Packages.h>
  47. #include    <Quickdraw.h>
  48. #include    <Resources.h>
  49. #include    <Script.h>
  50. #include    <ToolUtils.h>
  51. #include    <Windows.h>
  52.  
  53. #include "configrec.h"
  54. #include "whatami.h"
  55. #include    "VSkeys.h"
  56. #include    "wind.h"
  57. #include    "prefs.h"
  58. #include "user.h"
  59. #include "util.h"
  60. #include "bkgr.h"
  61. #include "maclook.h"
  62. #include "netevent.h"
  63. #include "vsinterf.h"
  64. #include "menu.h"
  65. #include "vrrgmac.h"
  66. #include "tekrgmac.h"
  67. #include "rsmac.h"
  68. #include "ser.h"                /* BYU 2.4.15 MPW */
  69.  
  70. #ifdef MPW
  71. #include "mpw.h"
  72. #endif
  73.  
  74. /*
  75.  * Event Auxilliary Defines
  76.  */
  77.  
  78. #define KCHR_resource    12000    /* BYU 2.4.12 */
  79.  
  80. #define WaitEvents    10        /* Mouse and Keyboard Dn Events for the Wait4Mouse() */
  81. #define    BScode        51        /* This is the Keycode for Backspace */
  82. #define KPlowest    65        /* This is the last code before the KP */
  83.  
  84. #define switchEvt     1        /* Switching event (suspend/resume )  for app4evt */
  85.  
  86. #define WAITTICKS    3L        /* One (Half) now tenth now 1/20th second for the first try.... */
  87. /*
  88.  *    Font Height and width constants
  89.  */
  90.  
  91. #define Fwidth 6
  92.  
  93.  
  94.  
  95. /*
  96.  *    Window constraints
  97.  */
  98.  
  99.  
  100. #define MAXWINDOWWIDTH  18+Fwidth*80
  101.  
  102. /*
  103.  * Window Defines
  104.  */
  105.  
  106. #define NO_WINDOW    0
  107. #define DEC_WINDOW    1
  108. #define TEK_WINDOW    2
  109.  
  110. /* Macro Defines */
  111. #define MACRO_IP        0xff    /* Send IP number here */
  112. #define MACRO_LINES        0xfe    /* Send # of lines here */
  113.  
  114.  
  115. /* need some menu defines for enableing/disableing the edit menu */
  116.  
  117. #define    NMENUS    8            /*    We have NMENUS menus right now */
  118. #define Edit        2        /*  Edit Menu's Position */
  119. #define    EDundo        1
  120. #define EDcut        3
  121. #define EDcopy        4        /* Edit Menu: Copy */
  122. #define EDpaste        5        /* Edit Menu: Paste */
  123. #define EDclear        6        /* Edit Menu: Clear */
  124. #define EDcopyt        7        /* Edit Menu: Copy Table */
  125. #define EDmacros    9        /* Edit Menu: Macros */
  126. #define EDprefs        10        /* Edit Menu: Preferences */
  127.  
  128. /*
  129.  * ASCII character set defines
  130.  */
  131.  
  132. #define ESC            0x1b    /* the escape character */
  133. #define    BS            0x08    /* the backspace character */
  134. #define DEL            0x7f    /* the delete character */
  135. #define CR            0x0d    /* the carriage return character */
  136. #define LF            0x0a    /* the line feed character */
  137. #define    KILLCHAR    0x15    /* the character to kill the local line with */
  138.  
  139. #define Edit        2        /* BYU 2.4.11 - Edit Menu's Position */
  140. #define EDcopy        4        /* BYU 2.4.11 - Edit Menu: Copy */
  141. #define EDcopyt        7        /* BYU 2.4.11 - Edit Menu: Copy Table */
  142.  
  143. #define    Fil            1        /* BYU 2.4.11 - File Menu's Position */
  144. #define FLprint        12        /* BYU 2.4.11 - File Menu: Print Selection */
  145.  
  146. extern int RSTextSelected();    /* BYU 2.4.11 */
  147. extern void RScursblinkoff();    /* BYU 2.4.11 */
  148. extern void RScursblink();        /* BYU 2.4.11 */
  149. extern void DoTheMenuChecks();
  150. /*
  151.  *    Type declarations for Globals
  152.  */
  153.  
  154. EventRecord
  155.     myEvent;        /* Event Record for main loop */
  156. WindowPeek
  157.     myfrontwindow=0L;    /* window pointer for changing the pointer */
  158. GrafPtr
  159.     whichWindow;    /* window pointer for event loop */
  160. short                /* BYU 2.4.11 */
  161.     cursorBlink,    /* BYU 2.4.11 - 0 = noblink, 1 = blink */
  162.     cursorType,        /* BYU 2.4.11 - 0 = block, 1 = underscore, 2 = vertical line */
  163.     whichKCHR;        /* BYU 2.4.12 */
  164. int
  165.     myfronttype=NO_WINDOW,        /* what kinda window is the front one */
  166.     myfrontvs=0,    /* what is the VS # of the window */
  167.     ctrl=0x100,        /* Key option to use as control */
  168.     suspended=FALSE,/* Are we in the air??? */
  169.     mapTilde=1,        /* Mapping the Tilde, Mapping the Tilde, I'll go a Mapping the Tilde */
  170.     code;            /* code used in mouse operations */
  171. long
  172.     JuggTicks;        /* How many ticks to wait when Juggling */
  173. Handle hKCHR;        /* BYU 2.4.12 - Handle for keyboard mapping stuff */
  174. RgnHandle
  175.     myfrontRgn=0L;    /* Handle to the region of the window to scope for stuff */
  176. Cursor
  177.     *lastCursor=0L;
  178. char
  179.     allthekeys[16];    /* Someplace to put the keymap */
  180.  
  181. #if 0                                    /* BYU 2.4.12 */
  182. int langnum;
  183. #endif                                    /* BYU 2.4.12 */
  184.  
  185. extern MenuHandle myMenus[NMENUS];
  186. extern void AdjustMenus(),ftppi();        /* BYU */
  187.  
  188. unsigned char *macro[10];    /* the wonderful macro package .... */
  189.  
  190. /*
  191.  *    Declarations for constant variables
  192.  */
  193.  
  194. unsigned char kpxlate[2][62] =
  195.   /* table for translating virtual scan codes to internal codes for
  196.     special keys. */
  197.   {
  198.       {        /* virtual key code */
  199.         VSKP,    /* $41 */
  200.         VSRT,    /* $42 (Mac+) */
  201.         VSF4,        /* $43 (ADB) */
  202.         0,        /* $44 */
  203.         VSKC,        /* $45 (ADB std) */
  204.         VSLT,    /* $46 (Mac+) */
  205.         VSF1,    /* $47 */
  206.         VSDN,    /* $48 (Mac+) */
  207.         0,        /* $49 */
  208.         0,        /* $4A */
  209.         VSF3,        /* $4B (ADB) */
  210.         VSKE,    /* $4C */
  211.         VSUP,    /* $4D (Mac+) */
  212.         VSKM,        /* $4E */
  213.         0,        /* $4F */
  214.         0,        /* $50 */
  215.         VSF2,        /* $51 (ADB) */
  216.         VSK0,    /* $52 */
  217.         VSK1,    /* $53 */
  218.         VSK2,    /* $54 */
  219.         VSK3,    /* $55 */
  220.         VSK4,    /* $56 */
  221.         VSK5,    /* $57 */
  222.         VSK6,    /* $58 */
  223.         VSK7,    /* $59 */
  224.         0,        /* $5A */
  225.         VSK8,    /* $5B */
  226.         VSK9,    /* $5C */
  227.         0,        /* $5D */
  228.         0,        /* $5E */
  229.         0,        /* $5F */
  230.         VSF10,    /* $60 */    /* BYU 2.4.12 */
  231.         VSF11,    /* $61 */    /* BYU 2.4.12 */
  232.         VSF12,    /* $62 */    /* BYU 2.4.12 */
  233.         VSF8,    /* $63 */    /* BYU 2.4.12 - was VSF3 */
  234.         VSF13,    /* $64 */    /* BYU 2.4.12 */
  235.         VSF14,    /* $65 */    /* BYU 2.4.12 */
  236.         0,        /* $66 */
  237.         VSF16,    /* $67 */    /* BYU 2.4.12 */
  238.         0,        /* $68 */
  239.         VSF18,    /* $69 */    /* BYU 2.4.12 */
  240.         0,        /* $6A */
  241.         VSF19,    /* $6B */    /* BYU 2.4.12 */
  242.         0,        /* $6C */
  243.         VSF15,    /* $6D */    /* BYU 2.4.12 */
  244.         0,        /* $6E */
  245.         VSF17,    /* $6F */    /* BYU 2.4.12 */
  246.         0,        /* $70 */
  247.         VSF20,    /* $71 */    /* BYU 2.4.12 */
  248.         VSHELP,    /* $72 */    /* BYU 2.4.12 */
  249.         VSHOME,    /* $73 */    /* BYU 2.4.12 */
  250.         VSPGUP,    /* $74 */    /* BYU 2.4.12 */
  251.         VSDEL,    /* $75 (ADB ext) */        /* BYU 2.4.12 - was 0x7f */
  252.         VSF9,    /* $76 */    /* BYU 2.4.12 - was VSF4 */
  253.         VSEND,    /* $77 */    /* BYU 2.4.12 */
  254.         VSF7,    /* $78 */    /* BYU 2.4.12 - was VSF2 */
  255.         VSPGDN,    /* $79 */    /* BYU 2.4.12 */
  256.         VSF6,    /* $7A */    /* BYU 2.4.12 - was VSF1 */
  257.         VSLT,    /* $7B */
  258.         VSRT,    /* $7C */
  259.         VSDN,    /* $7D */
  260.         VSUP    /* $7E */
  261.       },
  262.       {
  263.         VSKP,    /* $41 */
  264.         VSF4,    /* $42 (Mac+) */
  265.         VSF4,        /* $43 (ADB) */
  266.         0,        /* $44 */
  267.         VSKC,        /* $45 (ADB) */
  268.         VSKC,    /* $46 (Mac+) */
  269.         VSF1,    /* $47 */
  270.         VSF2,    /* $48 */
  271.         0,        /* $49 */
  272.         0,        /* $4A */
  273.         VSF3,        /* $4B */
  274.         VSKE,    /* $4C */
  275.         VSF3,    /* $4D */
  276.         VSKM,        /* $4E */
  277.         0,        /* $4F */
  278.         0,        /* $50 */
  279.         VSF2,        /* $51 */
  280.         VSK0,    /* $52 */
  281.         VSK1,    /* $53 */
  282.         VSK2,    /* $54 */
  283.         VSK3,    /* $55 */
  284.         VSK4,    /* $56 */
  285.         VSK5,    /* $57 */
  286.         VSK6,    /* $58 */
  287.         VSK7,    /* $59 */
  288.         0,        /* $5A */
  289.         VSK8,    /* $5B */
  290.         VSK9,    /* $5C */
  291.         0,        /* $5D */
  292.         0,        /* $5E */
  293.         0,        /* $5F */
  294.         VSF10,    /* $60 */    /* BYU 2.4.12 */
  295.         VSF11,    /* $61 */    /* BYU 2.4.12 */
  296.         VSF12,    /* $62 */    /* BYU 2.4.12 */
  297.         VSF8,    /* $63 */    /* BYU 2.4.12 - was VSF3 */
  298.         VSF13,    /* $64 */    /* BYU 2.4.12 */
  299.         VSF14,    /* $65 */    /* BYU 2.4.12 */
  300.         0,        /* $66 */
  301.         VSF16,    /* $67 */    /* BYU 2.4.12 */
  302.         0,        /* $68 */
  303.         VSF18,    /* $69 */    /* BYU 2.4.12 */
  304.         0,        /* $6A */
  305.         VSF19,    /* $6B */    /* BYU 2.4.12 */
  306.         0,        /* $6C */
  307.         VSF15,    /* $6D */    /* BYU 2.4.12 */
  308.         0,        /* $6E */
  309.         VSF17,    /* $6F */    /* BYU 2.4.12 */
  310.         0,        /* $70 */
  311.         VSF20,    /* $71 */    /* BYU 2.4.12 */
  312.         VSHELP,    /* $72 */    /* BYU 2.4.12 */
  313.         VSHOME,    /* $73 */    /* BYU 2.4.12 */
  314.         VSPGUP,    /* $74 */    /* BYU 2.4.12 */
  315.         VSDEL,    /* $75 (ADB ext) */        /* BYU 2.4.12 - was 0x7f */
  316.         VSF9,    /* $76 */    /* BYU 2.4.12 - was VSF4 */
  317.         VSEND,    /* $77 */    /* BYU 2.4.12 */
  318.         VSF7,    /* $78 */    /* BYU 2.4.12 - was VSF2 */
  319.         VSPGDN,    /* $79 */    /* BYU 2.4.12 */
  320.         VSF6,    /* $7A */    /* BYU 2.4.12 - was VSF1 */
  321.         VSLT,    /* $7B */
  322.         VSRT,    /* $7C */
  323.         VSDN,    /* $7D */
  324.         VSUP    /* $7E */
  325.       }
  326.   };
  327.  
  328. extern SysEnvRec theWorld;        /* BYU 2.4.12 - System Environment record */
  329.  
  330. extern Rect
  331.     dragRect;        /* Where it is legal to drag ourselves */
  332.  
  333. extern long
  334.     SysScriptKeys,
  335.     SysScriptIcon;
  336.  
  337. extern WindRec
  338.     console,
  339.     ftplog,
  340.     *screens;
  341.  
  342. extern short slip_connection;    /* BYU 2.4.16 */
  343.  
  344. extern int
  345.     numwindows,                /* The number of windows now from Maclook */
  346.     ginon,
  347.     xferon,
  348.     whichMenus,
  349.     ScriptManager,
  350.     Juggling,        /* Are we Juggling?????    */
  351.     scrn;
  352. extern Cursor
  353.     *graphcurs,        /* Cursor when in graphic window */
  354.     *gincurs,        /* Cursor when in graphics input mode */
  355.     *xfercurs,        /* Cursor when in transfer mode */
  356.     *normcurs,        /* Cursor for non-transfer normal mode */
  357.     *textcurs,        /* Cursor for text mode */
  358.     *poscurs,        /* Cursor for positioning mode */
  359.     *watchcurs;        /* Cursor for time-taking operations */
  360.  
  361. void optionKeys        /* BYU 2.4.18 - put this procedure back in */
  362.   (
  363.     void
  364.   )
  365. {
  366.     int err;
  367.  
  368.     SysScriptKeys = GetScript(smRoman, smScriptKeys);
  369.     SysScriptIcon = GetScript(smRoman, smScriptIcon);
  370.  
  371.  
  372.     if (!(Prefs.optKeys && ScriptManager))
  373.         return;
  374.  
  375.     err= SetScript( smRoman, smScriptKeys, 12000);
  376.     if (err)
  377.         return;
  378.     err= SetScript( smRoman, smScriptIcon, 12000);
  379.     if (err)
  380.         return;
  381.     KeyScript(smRoman);
  382.  
  383.     putln("OPTIONAL option key processing installed");
  384. }
  385.  
  386. void optionKeysOff        /* BYU 2.4.18 - put this procedure back in */
  387.   (
  388.     void
  389.   )
  390. {
  391.  
  392.     int err;
  393.  
  394.     if (!ScriptManager)
  395.         return;
  396.  
  397.     if  (!Prefs.optKeys) return;
  398.     
  399.     
  400.     err= SetScript( smRoman, smScriptKeys, SysScriptKeys);
  401.     if (err)
  402.         return;
  403.     err= SetScript( smRoman, smScriptIcon, SysScriptIcon);
  404.     if (err)
  405.         return;
  406. /*    KeyScript(smRoman);   */
  407. }
  408.  
  409. void setmacro                /* Set macro number <n> to the value of s */
  410.   (
  411.     int n,
  412.     unsigned char *s
  413.   )
  414. {
  415.     unsigned char *p;
  416.     int num=0, pos=0, escape=0;
  417.  
  418.     if (n<0  || n>9)
  419.         return;
  420.  
  421.     p=macro[n];
  422.  
  423.     while ( *s) {
  424.         if (escape) {
  425.             escape=0;
  426.             switch (*s) {
  427.                 case 'i':
  428.                     if ( pos >0) {
  429.                         *p++=num;
  430.                         *p++=*s;
  431.                         pos=0;
  432.                         }
  433.                     *p++=MACRO_IP;
  434.                     break;
  435.                 case '#':
  436.                     if ( pos >0) {
  437.                         *p++=num;
  438.                         *p++=*s;
  439.                         pos=0;
  440.                         }
  441.                     *p++=MACRO_LINES;
  442.                     break;
  443.                 case 'n':
  444.                     if ( pos >0) {
  445.                         *p++=num;
  446.                         *p++=*s;
  447.                         pos=0;
  448.                         }
  449.                     *p++='\012';
  450.                     break;
  451.                 case 'r':
  452.                     if ( pos >0) {
  453.                         *p++=num;
  454.                         *p++=*s;
  455.                         pos=0;
  456.                         }
  457.                     *p++='\015';
  458.                     break;
  459.                 case 't':
  460.                     if ( pos >0) {
  461.                         *p++=num;
  462.                         *p++=*s;
  463.                         pos=0;
  464.                         }
  465.                     *p++='\t';
  466.                     break;
  467.                 case '"':
  468.                     if ( pos >0) {
  469.                         *p++=num;
  470.                         *p++=*s;
  471.                         pos=0;
  472.                         }
  473.                     *p++='\"';
  474.                     break;
  475.  
  476.                         
  477.                 case '\\':
  478.                     if ( pos >0) {
  479.                         *p++=num;
  480.                         escape=1;
  481.                         pos=0;
  482.                         num=0;
  483.                         }
  484.                     else
  485.                         *p++='\\';
  486.                     break;
  487.                 default:
  488.                     if (*s <='9' && *s >='0' && pos <3) {
  489.                         num= num*8+( *s -'0');
  490.                         pos++;
  491.                         escape=1;
  492.                         }
  493.                     else {
  494.                         if (pos ==0 && num==0) {
  495.                             *p++='\\';
  496.                             *p++=*s;
  497.                             }
  498.                         else {
  499.                             *p++=num;
  500.                             pos= 0;
  501.                             s--;            /* back up the buffer. */
  502.                             }
  503.                         }
  504.                     break;
  505.                 }
  506.             }
  507.         else {
  508.             if (*s=='\\') {
  509.                 num=0;
  510.                 pos=0;
  511.                 escape=1;
  512.                 }
  513.             else
  514.                 *p++=*s;
  515.             }
  516.         s++;
  517.         }
  518.  
  519.     if (pos >0) *p++=num;
  520.     *p=0;
  521. } /* setmacro */
  522.  
  523. void initmacros
  524.   (
  525.     void
  526.   )
  527. {
  528.     int i;
  529.  
  530.     for (i=0; i<10 ; i++) {
  531.         (Ptr) macro[i] = NewPtr(256);
  532.         if (macro[i]== NULL) {
  533.             OtherError("No space for macro storage", "Fatal error");
  534.             quit();
  535.             }
  536.         setmacro( i, "");
  537.         }
  538. }
  539.  
  540. void initKeyBoardMapping(void) {                            /* BYU 2.4.13 */
  541.     long myscript;                                            /* BYU 2.4.13 */
  542.                                                             /* BYU 2.4.13 */
  543. /* First try to use the default System 7 keyboard mapping.    /* BYU 2.4.13 */
  544. /* When that fails use the application's KCHR resource if     /* BYU 2.4.13 */
  545. /* it's the only one in town.                                /* BYU 2.4.13 */
  546.                                                             /* BYU 2.4.13 */
  547. /* Release the previously selected resource.                  /* BYU 2.4.13 */
  548.     if (hKCHR)                                                /* BYU 2.4.13 */
  549.         ReleaseResource(hKCHR);                                /* BYU 2.4.13 */
  550.                                                             /* BYU 2.4.13 */
  551.     if (Prefs.systemKCHR) {                                    /* BYU 2.4.18 */
  552.         myscript = GetEnvirons(smKeyScript);                /* BYU 2.4.18 */
  553.         if (myscript && ScriptManager) {                    /* BYU 2.4.18 */
  554.             whichKCHR = GetScript(myscript,smScriptKeys);    /* BYU 2.4.18 */
  555.             if (whichKCHR)                                    /* BYU 2.4.18 */
  556.                 hKCHR = GetResource('KCHR',whichKCHR);        /* BYU 2.4.18 */
  557.         }                                                    /* BYU 2.4.18 */
  558.         if (!hKCHR) {                                        /* BYU 2.4.18 */
  559.             whichKCHR = KCHR_resource;                        /* BYU 2.4.18 */
  560.             hKCHR = GetResource('KCHR', whichKCHR);            /* BYU 2.4.18 */
  561.         }                                                    /* BYU 2.4.18 */
  562.     } else {                                                /* BYU 2.4.18 */
  563.                                                             /* BYU 2.4.18 */
  564. /* Use the application KCHR resource */                        /* BYU 2.4.18 */
  565.         whichKCHR = KCHR_resource;                            /* BYU 2.4.13 */
  566.         hKCHR = GetResource('KCHR', whichKCHR);                /* BYU 2.4.13 */
  567.                                                             /* BYU 2.4.13 */
  568. /* If mapping "option" to "control" is not active, or the     /* BYU 2.4.13 */
  569. /* application  KCHR resource has been removed, use the     /* BYU 2.4.13 */
  570. /* system KCHR resource for mapping keys.                     /* BYU 2.4.13 */
  571.         if (!hKCHR) {                                            /* BYU 2.4.13 */
  572.             myscript = GetEnvirons(smKeyScript);                /* BYU 2.4.13 */
  573.             if (myscript && ScriptManager) {                    /* BYU 2.4.13 */
  574.                 whichKCHR = GetScript(myscript,smScriptKeys);    /* BYU 2.4.13 */
  575.                 if (whichKCHR)                                    /* BYU 2.4.13 */
  576.                     hKCHR = GetResource('KCHR',whichKCHR);        /* BYU 2.4.13 */
  577.             }                                                    /* BYU 2.4.13 */
  578.         }                                                    /* BYU 2.4.13 */
  579.     }                                                        /* BYU 2.4.13 */
  580.                                                             /* BYU 2.4.13 */
  581.     if (!hKCHR)                                                /* BYU 2.4.13 */
  582.         whichKCHR = 0;                                        /* BYU 2.4.13 */
  583. }
  584.  
  585. void initEvents
  586.   (
  587.     void
  588.   )
  589. {
  590.  
  591.     initmacros();
  592.  
  593.     if (theWorld.systemVersion < 0x0700)    /* BYU 2.4.18 */
  594.         optionKeys();                        /* BYU 2.4.18 */
  595.  
  596. #if 0    /* BYU - disabled per Scott@NCSA */
  597.     optionKeys();
  598. #endif
  599.  
  600.     FlushEvents(everyEvent - diskEvt,0);    /* Don't Let 'em get off without seeing it. */
  601.  
  602.     JuggTicks=WAITTICKS;
  603.  
  604. #if 0                        /* BYU 2.4.15 - initialized in "environ.c" */
  605.     Juggling = 0;
  606. #endif                        /* BYU 2.4.15 */
  607.  
  608.     mapTilde = Prefs.mapTilde;
  609.     if (GetTrapAddress( 0x60) != GetTrapAddress( 0x9f) ) {
  610.         Juggling = 1;
  611.         putln("Juggling!");        /* BYU */
  612.         WaitNextEvent(everyEvent, &myEvent, JuggTicks, 0L);
  613.         WaitNextEvent(everyEvent, &myEvent, JuggTicks, 0L);
  614.         }
  615.  
  616.     hKCHR = 0;                                    /* BYU 2.4.13 */
  617.     initKeyBoardMapping();                        /* BYU 2.4.12 */
  618.  
  619. #if 0                                            /* BYU 2.4.12 */
  620.     else Juggling =0;                            /* BYU LSC - Currently only check for Juggler */
  621.     putln("Done with initEvents()");
  622. #endif                                            /* BYU 2.4.12 */
  623. }
  624.  
  625. void JTime
  626.   (
  627.     int i
  628.   )
  629.   {
  630.     if (i >= 0)
  631.         JuggTicks = i;
  632.   }
  633.  
  634. int updateCursor
  635.   (
  636.     int force
  637.   )
  638. {
  639.     static long lastPoint;
  640.     static int optwasdown;
  641.     int optDown;
  642.     long myPoint;
  643.  
  644.     if (myfrontwindow) {                    /* BYU 2.4.11 */
  645.         SetPort((GrafPtr) myfrontwindow);    /* BYU 2.4.11 */
  646.     } else {                                /* BYU 2.4.11 */
  647.         SetCursor(normcurs);                /* BYU 2.4.11 */
  648.         return(0);                            /* BYU 2.4.11 */
  649.     }                                        /* BYU 2.4.11 */
  650.  
  651.     GetMouse((Point *) &myPoint);
  652.  
  653.     GetKeys((KeyMap) allthekeys);
  654.     optDown = allthekeys[7] &4;
  655.  
  656.     if ( (!force) && (myPoint == lastPoint) && (optDown ==optwasdown))
  657.         return(0);
  658.  
  659.     if (force)
  660.         lastCursor=0L;
  661.     if (ginon) {
  662.         if (lastCursor!= gincurs) {
  663.             SetCursor( gincurs);
  664.             lastCursor = gincurs;
  665.             }
  666.         return(1);
  667.         }
  668.  
  669.     if (xferon && !optDown) {
  670.         if  (lastCursor!= xfercurs) {
  671.             SetCursor( xfercurs);
  672.             lastCursor = xfercurs;
  673.             }
  674.         return(1);
  675.         }
  676.  
  677.     switch (myfronttype) {
  678.         case DEC_WINDOW:
  679.             if (RSmouseintext( myfrontvs, myPoint)) {
  680.                 if (optDown) {                /* Option key is down */
  681.                     if (lastCursor !=poscurs) {
  682.                         lastCursor  =poscurs;
  683.                         SetCursor(poscurs);
  684.                         }
  685.                 } else {
  686.                     if (lastCursor !=textcurs) {
  687.                         lastCursor  =textcurs;
  688.                         SetCursor(textcurs);
  689.                         }
  690.                     }
  691.             } else {
  692.                 if (lastCursor !=normcurs) {
  693.                     lastCursor  =normcurs;
  694.                     SetCursor(normcurs);
  695.                     }
  696.             }
  697.             break;
  698.         case TEK_WINDOW:
  699.             LocalToGlobal((Point *) &myPoint);
  700.             if (ptinrgn((Point *) &myPoint, myfrontwindow->contRgn)) {
  701.                 if (lastCursor !=graphcurs) {
  702.                     lastCursor  =graphcurs;
  703.                     SetCursor(graphcurs);
  704.                     }
  705.             } else {
  706.                 if (lastCursor !=normcurs) {
  707.                     lastCursor  =normcurs;
  708.                     SetCursor(normcurs);
  709.                     }
  710.             }
  711.             break;
  712.         case NO_WINDOW:
  713.         default:
  714.             if (force) {
  715.                 SetCursor( normcurs);
  716.                 lastCursor= normcurs;
  717.                 }
  718.         }
  719.     lastPoint=myPoint;
  720.     optwasdown=optDown;
  721.     return(0);
  722. }
  723.  
  724. void NoWindow
  725.   (
  726.     void
  727.   )
  728. {
  729.         myfrontwindow=0L;
  730.         myfronttype=NO_WINDOW;
  731.         myfrontRgn=0L;
  732.         updateCursor(1);
  733. }
  734.  
  735. int sendmacro                /* send macro number n */
  736.   (
  737.     int n
  738.   )
  739. {
  740.     unsigned char temp[300], *mp, *tp;
  741.     extern unsigned char myipnum[4];
  742.  
  743.     if (n<0 || n>9) return(-1);
  744.  
  745.     tp = temp;
  746.     mp = macro[n];
  747.     while ( *mp) {
  748.         if ( *mp==MACRO_IP) {
  749.             sprintf(tp,"%d.%d.%d.%d", myipnum[0], myipnum[1], myipnum[2], myipnum[3]);
  750.             tp+=strlen(tp);
  751.             mp++;
  752.             }
  753.         else if ( *mp==MACRO_LINES) {
  754.             sprintf(tp,"%d", VSgetlines( screens[scrn].vs));
  755.             tp+=strlen(tp);
  756.             mp++;
  757.             }
  758.         else if (screens[scrn].ftpstate) {                                /* BYU 2.4.16 */
  759.             if (*mp == CR) {                                            /* BYU 2.4.16 */
  760.                 parse( &screens[scrn],(unsigned char *) "\015\012",2);    /* BYU 2.4.16 */
  761.                 screens[scrn].kbbuf[ screens[scrn].kblen++ ] = 0;        /* BYU 2.4.16 */
  762.                 ftppi(screens[scrn].kbbuf);                                /* BYU 2.4.16 - ftp client */
  763.                 screens[scrn].kblen=0;                                    /* BYU 2.4.16 */
  764.                 mp++;                                                    /* BYU 2.4.16 */
  765.             } else {                                                    /* BYU 2.4.16 */
  766.                 screens[scrn].kbbuf[ screens[scrn].kblen++ ] = *mp;        /* BYU 2.4.16 */
  767.                 parse( &screens[ scrn], mp++, 1);                        /* BYU 2.4.16 */
  768.             }                                                            /* BYU 2.4.16 */
  769.         } else *tp++=*mp++;                                                /* BYU 2.4.16 */
  770.     }                                                                    /* BYU 2.4.16 */
  771.     *tp=0;                        /* Gotta have a nul! */
  772.     tp= temp;
  773.  
  774.     if (!screens[scrn].ftpstate &&                                         /* BYU 2.4.16 */
  775.         (screens[scrn].connectionType == 0 || slip_connection)) {        /* BYU 2.4.16 */
  776.  
  777.         netpush( screens[scrn].port);                                    /* BYU 2.4.16 */
  778.  
  779.         if (screens[scrn].lmflag)     /* need to flush buffer */            /* BYU 2.4.16 */
  780.             {                                                            /* BYU 2.4.16 */
  781.             netwrite(screens[scrn].port,screens[scrn].kbbuf,screens[scrn].kblen);    /* BYU 2.4.16 */
  782.             screens[scrn].kblen=0;                                        /* BYU 2.4.16 */
  783.             }                                                            /* BYU 2.4.16 */
  784.     }                                                                    /* BYU 2.4.16 */
  785.  
  786.     if (!screens[scrn].ftpstate) {                                        /* BYU 2.4.16 */
  787.         netwrite(screens[scrn].port, tp, strlen((char *) tp) );            /* BYU 2.4.16 */
  788.     
  789.         if (screens[scrn].echo)
  790.             parse( &screens[scrn],tp, strlen((char *) tp) );            /* BYU 2.4.16 */
  791.     }                                                                    /* BYU 2.4.16 */
  792.  
  793.     return(0);
  794. }
  795.  
  796. long InterpretMessage(EventRecord *event) {                        /* BYU 2.4.12 */
  797.   long message;                                                    /* BYU 2.4.12 */
  798.   long state=0;                                                    /* BYU 2.4.12 */
  799.   short keycode;                                                /* BYU 2.4.12 */
  800.                                                                 /* BYU 2.4.12 */
  801. /* Default to the application KCHR resource.                    /* BYU 2.4.12 */
  802. /* If it is missing then try the current system resource.         /* BYU 2.4.12 */
  803.                                                                 /* BYU 2.4.12 */
  804.     if (whichKCHR)                                                /* BYU 2.4.12 */
  805.         hKCHR = GetResource('KCHR', whichKCHR);                    /* BYU 2.4.12 */
  806.     else                                                        /* BYU 2.4.12 */
  807.         return(event->message);                                    /* BYU 2.4.12 */
  808.                                                                 /* BYU 2.4.12 */
  809.     if (!hKCHR) {                                                /* BYU 2.4.12 */
  810.         message = event->message;                                /* BYU 2.4.12 */
  811.     } else {                                                    /* BYU 2.4.12 */
  812.         keycode = ((event->message>>8) & 0xff) |                 /* BYU 2.4.12 */
  813.             (event->modifiers & 0xff00);                        /* BYU 2.4.12 */
  814.         message = KeyTrans(*hKCHR, keycode, &state);            /* BYU 2.4.12 */
  815.         message = (message & 0xff) | (event->message & 0xff00);    /* BYU 2.4.12 */
  816.     }                                                            /* BYU 2.4.12 */
  817.                                                                 /* BYU 2.4.12 */
  818.   return(message);                                                /* BYU 2.4.12 */
  819. }                                                                /* BYU 2.4.12 */
  820.  
  821. void doKeys
  822.   (
  823.     void
  824.   )
  825. {
  826.     int ascii,code;
  827.     unsigned char sendch;
  828.     long menuEquiv;
  829.     short enterkey =0;
  830.         
  831.     ObscureCursor();
  832.  
  833. /* If the option key is not mapped to the control key            /* BYU 2.4 12 */
  834. /*   then map it per the KCHR resource                             /* BYU 2.4.12 */
  835. /*    if ((!Prefs.optKeys) && (myEvent.modifiers & optionKey))    /* BYU 2.4.12 */
  836. /*        myEvent.message = InterpretMessage(&myEvent);            /* BYU 2.4.12 */
  837.  
  838. /* Map all keys by the appropriate Script/KCHR resource.        /* BYU 2.4.12 */
  839.     myEvent.message = InterpretMessage(&myEvent);                /* BYU 2.4.13 */
  840.  
  841.     ascii = myEvent.message & charCodeMask;
  842.     code = (myEvent.message & keyCodeMask) >> 8;
  843.     if ((myEvent.modifiers & cmdKey) && (menuEquiv = MenuKey(ascii))) {
  844.         docommand(menuEquiv,myEvent.modifiers);
  845.         return;
  846.     }
  847.  
  848.     if ((myEvent.modifiers & ( optionKey | controlKey)) && (ascii==32))
  849.                 ascii=0;            /* ASCII nul value for command-spacebar */
  850.  
  851.     if (myEvent.modifiers & cmdKey)  {
  852.         if (ascii==';' ) {            /* debugging information on cmd-; */
  853.             int i;
  854.             char temp[50];
  855.             for (i=0; i<numwindows; i++) {
  856.                 sprintf(temp, "[%d]  %d (%d) %s", i,screens[i].port, screens[i].active, screens[i].machine);
  857.                 putln(temp);
  858.                 }
  859.             }
  860.         }         
  861.  
  862.     if (screens[scrn].corpse)
  863.         return;
  864.  
  865.     if (myEvent.modifiers & cmdKey)  {
  866.         if (ascii >='0' && ascii <='9' )  {            /* handle key macros */
  867.             sendmacro( ascii-'0');
  868.             return;
  869.             }
  870.         }
  871.  
  872.     if (numwindows<1 || ((myEvent.modifiers & cmdKey ) && whichMenus))
  873.         return;
  874.  
  875. #if 0                                                /* BYU 2.4.12 */
  876.     if (code == 0x77) {                                /* Flush on <end> */
  877.         FlushNetwork(scrn);
  878.         return;
  879.         }
  880. #endif                                                /* BYU 2.4.12 */
  881.  
  882.     if (!screens[scrn].ftpstate && (code >= KPlowest)) {        /* BYU - Handle Keypad */
  883.         int shifted;
  884.         shifted = (myEvent.modifiers & shiftKey) != 0;
  885.         if (theWorld.keyBoardType == envStandADBKbd)    /* BYU 2.4.12 */
  886.     
  887.             if (code == 0x45)
  888.                 code = 0x4e;
  889.             else if (code == 0x4e)
  890.                 code = 0x45;                
  891.         ascii = kpxlate[shifted][code - KPlowest];
  892.         VSkbsend(screens[scrn].vs, (unsigned char) ascii, screens[scrn].echo);
  893.         return;
  894.       }
  895.  
  896.  
  897.     /* BSD-like mapping.... if we don't want this, set chars to something >128 and it wont work */
  898.     if (ascii == screens[scrn].TELstop)  {
  899.         screens[scrn].enabled = 0;
  900.         return;
  901.         }
  902.  
  903.     if (ascii == screens[scrn].TELgo) {
  904.         screens[scrn].enabled = 1;
  905.         return;
  906.         }
  907.  
  908.  
  909.         
  910.     if (ascii == screens[scrn].TELip)  {
  911.         netpush(screens[scrn].port);
  912.         netwrite(screens[scrn].port, "\377\364",2);
  913.         screens[ scrn].timing = 1;                            /* set emulate to TMwait */
  914.         netwrite(screens[scrn].port, "\377\375\006",3);        /* send TM */
  915.         if (screens[scrn].lmflag) 
  916.             screens[scrn].kblen=0;
  917.         return;
  918.         }
  919.  
  920.  
  921.  
  922.     ascii &= 0x7f;        /* Don't allow those bluming option chars */
  923.     
  924.     if (ascii == '`' && mapTilde) ascii = ESC;                    /* Map '`' to ESC */
  925.  
  926.     if ((screens[scrn].bsdel) && (code==BScode)) ascii=DEL;
  927.  
  928.     if (myEvent.modifiers & (optionKey | cmdKey)) {    /* Map control chars */
  929.         if (ascii == ESC)                            /* the '`' remains the same */
  930.             ascii = '`';
  931.         else
  932.             if (code == BScode) {                    /* Swap only the true bksp */
  933.                 if (screens[scrn].bsdel) ascii=BS;
  934.                     else ascii=DEL;
  935.                 }
  936.         else {
  937.             if (Prefs.optKeys || !Prefs.cmdKeys)    /* Option or command remapped to control */
  938.                 ascii &= 0x1f;                        /* All other chars are ctrl */
  939.             }
  940.         }
  941.  
  942.  
  943.     if (screens[scrn].ftpstate)                            /* BYU - ftpclient */
  944.         {                                                /* BYU */
  945.         if (ascii>31 && ascii <127 && code<KPlowest)    /* BYU - add these chars to buffer */
  946.             {                                            /* BYU */
  947.             if (screens[scrn].kblen < (MAXKB -1))         /* BYU - Add to buffer if not full */
  948.                 {                                        /* BYU */
  949.                 screens[scrn].kbbuf[ screens[scrn].kblen++ ] = ascii;    /* BYU */
  950.                 sendch=ascii;                            /* BYU */
  951.                 parse( &screens[ scrn], &sendch, 1);    /* BYU */
  952.                 }                                        /* BYU */
  953.             else                                         /* BYU */
  954.                 SysBeep(4);                                /* BYU - buffer full */
  955.             }                                            /* BYU */
  956.         else                                            /* BYU - not printable char */
  957.             {                                            /* BYU */
  958.             if ( code == BScode )                         /* BYU */
  959.                 {                                        /* BYU */
  960.                 if (screens[scrn].kblen>0)                 /* BYU */
  961.                     {                                    /* BYU */
  962.                     screens[scrn].kblen--;                    /* BYU */
  963.                     parse( &screens[scrn],"\010 \010",3);    /* BYU */
  964.                     }                                        /* BYU */
  965.                 }                                        /* BYU */
  966.             else if (ascii == CR)                        /* BYU */
  967.                 {                                        /* BYU */
  968.                 parse( &screens[scrn],"\015\012",2);                /* BYU */
  969.                 screens[scrn].kbbuf[ screens[scrn].kblen++ ] = 0;    /* BYU */
  970.                 ftppi(screens[scrn].kbbuf);                            /* BYU - ftp client */
  971.                 screens[scrn].kblen=0;                    /* BYU */
  972.                 }                                        /* BYU */
  973.             else if (ascii == KILLCHAR)                 /* BYU */
  974.                 {                                        /* BYU */
  975.                 while (screens[scrn].kblen >0)             /* BYU */
  976.                     {                                        /* BYU */
  977.                     parse( &screens[scrn],"\010 \010",3);    /* BYU */
  978.                     screens[scrn].kblen--;                    /* BYU */
  979.                     }                                    /* BYU */
  980.                 }
  981.             }
  982.         return;                                            /* BYU */
  983.         }
  984.  
  985.     else if (screens[scrn].lmflag)    /* I'm in line-Mode... aren't you?? */
  986.         {    
  987.         if (screens[scrn].echo && ! screens[scrn].halfdup)        /* Handle local ECHOs */
  988.  
  989.             if (ascii>31 && ascii <127 && code<KPlowest)    /* add these chars to buffer */
  990.                 {
  991.                 if (screens[scrn].kblen < (MAXKB -1))     /* Add to buffer if not full */
  992.                     screens[scrn].kbbuf[ screens[scrn].kblen++ ] = ascii;
  993.                 else 
  994.                     {                
  995.                     netwrite( screens[scrn].port, screens[scrn].kbbuf, screens[scrn].kblen);    /* if full send buffer */
  996.                     screens[scrn].kbbuf[0]=ascii;
  997.                     screens[scrn].kblen=1;
  998.                     }
  999.     
  1000.                 sendch=ascii;
  1001.                 parse( &screens[ scrn], &sendch, 1);
  1002.                 if (!screens[scrn].halfdup)
  1003.                     return;                                /* OK, were set...*/
  1004.     
  1005.                 }
  1006.              else                    /* not printable char */
  1007.                 {
  1008.                 if ( code == BScode ) 
  1009.                     {
  1010.                     if (screens[scrn].kblen>0) 
  1011.                         {
  1012.                         screens[scrn].kblen--;
  1013.                         parse( &screens[scrn],"\010 \010",3);
  1014.                         }
  1015.                     return;
  1016.                     }
  1017.                 else if (ascii == CR)
  1018.                     {
  1019.                     char tt[50];
  1020.                     
  1021.                     netwrite( screens[scrn].port, screens[scrn].kbbuf, screens[scrn].kblen);
  1022.                     sprintf(tt,"length %i ",(int)screens[scrn].kblen);
  1023.                     putln(tt);
  1024.                     screens[scrn].kblen=0;
  1025.                     }
  1026.     
  1027.                 else if (ascii == KILLCHAR) 
  1028.                     {
  1029.                     while (screens[scrn].kblen >0) 
  1030.                         {
  1031.                         parse( &screens[scrn],"\010 \010",3);
  1032.                         screens[scrn].kblen--;
  1033.                         }
  1034.                     return;
  1035.                     }
  1036.  
  1037.                 else if (code <KPlowest) 
  1038.                     {
  1039.                     netwrite( screens[scrn].port, screens[scrn].kbbuf, screens[scrn].kblen);    /* if full send buffer */
  1040.                     screens[scrn].kblen=0;
  1041.                     
  1042.                     if (ascii !=CR) 
  1043.                         {
  1044.                         char crapp[5];
  1045.                         
  1046.                         if (ascii == 26)    /* job control */
  1047.                             {
  1048.                             sprintf(crapp,"%c%c",255,237);
  1049.                             netwrite(screens[scrn].port,crapp,2);
  1050.                             parse( &screens[scrn],"^",1);
  1051.                             parse( &screens[scrn], &sendch, 1);
  1052.                             return;
  1053.  
  1054.                             }
  1055.                         sendch='@'+ascii;
  1056.                         parse( &screens[scrn],"^",1);
  1057.                         parse( &screens[scrn], &sendch, 1);
  1058.                         }
  1059.                     }
  1060.                 }
  1061.             }
  1062.             
  1063.  
  1064.     else        /* BYU = was: if (!screens[scrn].lmflag ) */
  1065.         {
  1066.         if (screens[scrn].echo && ! screens[scrn].halfdup)        /* Handle local ECHOs */
  1067.             if (ascii>31 && ascii <127 && code<KPlowest)    
  1068.                 {
  1069.                 if (screens[scrn].kblen < (MAXKB -1))     /* Add to buffer if not full */
  1070.                     screens[scrn].kbbuf[ screens[scrn].kblen++ ] = ascii;
  1071.                 else 
  1072.                     {                    
  1073.                     netwrite( screens[scrn].port, screens[scrn].kbbuf,
  1074.                     screens[scrn].kblen);    /* if full send buffer */    
  1075.                     screens[scrn].kbbuf[ 0 ]=ascii;
  1076.                     screens[scrn].kblen=1;
  1077.                     }
  1078.                 sendch=ascii;
  1079.                 parse( &screens[ scrn], &sendch, 1);
  1080.                 if (!screens[scrn].halfdup)
  1081.                     return;                                /* OK, were set...*/
  1082.                 }
  1083.             else 
  1084.                 {
  1085.                 if ( code == BScode ) 
  1086.                     {
  1087.                     if (screens[scrn].kblen>0) 
  1088.                         {
  1089.                         screens[scrn].kblen--;
  1090.                         parse( &screens[scrn],"\010 \010",3);
  1091.                         }
  1092.                     return;
  1093.                     }
  1094.                 else if (ascii == KILLCHAR) 
  1095.                     {
  1096.                     while (screens[scrn].kblen >0) 
  1097.                         {
  1098.                         parse( &screens[scrn],"\010 \010",3);
  1099.                         screens[scrn].kblen--;
  1100.                         }
  1101.                     return;
  1102.                     }
  1103.         
  1104.                 else if (code <KPlowest) 
  1105.                     {
  1106.                     netwrite( screens[scrn].port, screens[scrn].kbbuf,
  1107.                     screens[scrn].kblen);    /* if full send buffer */
  1108.                     screens[scrn].kblen=0;
  1109.                     if (ascii !=CR) 
  1110.                         {
  1111.                         sendch='@'+ascii;
  1112.                         parse( &screens[scrn],"^",1);
  1113.                         parse( &screens[scrn], &sendch, 1);
  1114.                         }
  1115.                     }
  1116.                 }
  1117.             }
  1118.             
  1119.  
  1120.  
  1121.     
  1122.     if (ascii == '\015')                         /* BYU 2.4.18 - changed \n to \015 */
  1123.         {        /* Map CR->CRLF */
  1124.         netpush( screens[scrn].port);
  1125.         if ((!screens[scrn].lmflag) || (!screens[scrn].crmap)) netwrite(screens[scrn].port,"\015",1);
  1126.         ascii=screens[scrn].crmap;
  1127.         if (screens[scrn].echo) parse( &screens[scrn],"\012\015",2);
  1128.         if (screens[scrn].connectionType && !slip_connection)                /* BYU 2.4.18 */
  1129.             return;                                                            /* BYU 2.4.18 */
  1130.         }
  1131.  
  1132. #ifdef OLD_STUFF
  1133.     if (ascii == '\r')
  1134.         {
  1135.         netwrite(screens[scrn].port,"\r",1);
  1136.         netpush(screens[scrn].port);
  1137.         ascii = screens[scrn].crmap;
  1138.         if (screens[scrn].echo) parse (&screens[scrn],"\r\012",2);
  1139.         }
  1140. #endif
  1141.  
  1142.     if (screens[scrn].echo && screens[scrn].halfdup) 
  1143.         {
  1144.         sendch=ascii;
  1145.         parse( &screens[scrn], &sendch, 1);
  1146.         }
  1147.     
  1148.     sendch= ascii;
  1149.     netwrite(screens[scrn].port,&sendch,1);
  1150.     netpush(screens[scrn].port);                    /* DAMN PYRAMIDS! */
  1151.  
  1152. }
  1153.  
  1154. void DoEvents
  1155.   (
  1156.     void
  1157.   )
  1158. {
  1159.     Boolean gotOne;            /* Did we get an event */
  1160.     int vs;                    /* BYU 2.4.11 */
  1161.  
  1162.     if (Juggling)
  1163.         gotOne = WaitNextEvent(everyEvent, &myEvent, JuggTicks, 0L);
  1164.     else
  1165.       {
  1166.         SystemTask();                        /* love those desk acc. */
  1167.         gotOne = GetNextEvent(everyEvent, &myEvent);
  1168.       }
  1169.  
  1170.     if (gotOne) {
  1171.  
  1172. /* BYU 2.4.11 - Turn the cursor off when the human makes the slightest move. */
  1173.         if (cursorBlink) {                                /* BYU 2.4.11 */
  1174.             whichWindow = FrontWindow();                /* BYU 2.4.11 */
  1175.             if ( (vs=RSfindvwind(whichWindow)) >= 0)    /* BYU 2.4.11 */
  1176.                 if (vs == screens[scrn].vs)                /* BYU 2.4.11 */
  1177.                     if (!(myEvent.modifiers & cmdKey) &&    /* BYU 2.4.18 */
  1178.                         ((myEvent.what == keyDown) ||         /* BYU 2.4.18 */
  1179.                          (myEvent.what == autoKey)))        /* BYU 2.4.18 */
  1180.                         RScursblinkon(vs);                /* BYU 2.4.18 */
  1181.                     else                                /* BYU 2.4.18 */
  1182.                         RScursblinkoff(vs);                /* BYU 2.4.18 */
  1183.         }                                                /* BYU 2.4.11 */
  1184.  
  1185.         switch(myEvent.what) {
  1186.         case mouseDown:
  1187.             code = findwindow(pass(myEvent.where), &whichWindow);
  1188.             switch (code) {
  1189.             case inMenuBar:
  1190.                 docommand(menuselect(pass(myEvent.where)),myEvent.modifiers);
  1191.                 break;
  1192.             case inSysWindow:
  1193.                 SystemClick(&myEvent, whichWindow);
  1194.                 break;
  1195.             case inGoAway:
  1196.                 if (trackgoaway( whichWindow, pass(myEvent.where))) {
  1197.                     if (RSfindvwind(whichWindow)>=0) {
  1198.                         int i;
  1199.                         extern int findbyWind ();
  1200.  
  1201.                         i=findbyWind( whichWindow);            /* We need to know who */
  1202.                         if (i>=0) {
  1203.                             if ( screens[i].corpse)
  1204.                                 destroyport(i);
  1205.                             else {
  1206.                                 if ( !ReallyClose( i) ) break;
  1207.                                 netclose(screens[i].port);
  1208.                                 destroyport(i);
  1209.                                 }
  1210.                             }
  1211.                         NoWindow();
  1212.                         }
  1213.                     else if (MacRGfindwind( whichWindow) >=0) {
  1214.                         int i;
  1215.                         i= MacRGfindwind( whichWindow);
  1216.                         MacRGdestroy( i);
  1217.                         NoWindow();
  1218.                         }
  1219.                     else {
  1220.                         destroyGraphics( RGgetVG(whichWindow));
  1221.                         NoWindow();
  1222.                         }
  1223.                     }
  1224.                 break;
  1225.             case inDrag:
  1226.                 if ((whichWindow != FrontWindow()) &&
  1227.                         (!(myEvent.modifiers & cmdKey)) &&
  1228.                         (!(myEvent.modifiers & optionKey))) {
  1229.                     SelectWindow(whichWindow);
  1230.                     }
  1231.                 dragwindow(whichWindow, pass(myEvent.where), &dragRect);
  1232.                 break;
  1233.             case inZoomIn:
  1234.             case inZoomOut:
  1235.                 if (TrackBox( whichWindow, myEvent.where, code))
  1236.                     RSzoom( whichWindow, code, myEvent.modifiers & shiftKey);
  1237.                 break;
  1238.             case inGrow:
  1239.                 RSsize( whichWindow, (long *) &myEvent.where, myEvent.modifiers);
  1240.                 break;
  1241.             case inContent:
  1242.                 if (whichWindow != FrontWindow()) {
  1243.                     SelectWindow(whichWindow);
  1244.                     }
  1245.                 else
  1246.                     if (RSclick( whichWindow, (long *) &myEvent.where,
  1247.                             (myEvent.modifiers & shiftKey),
  1248.                             (myEvent.modifiers & optionKey)) <0) {
  1249.                         SetPort(whichWindow);
  1250.                         GlobalToLocal(&myEvent.where);
  1251.                         RGmousedown(whichWindow, &myEvent.where );
  1252.                         }
  1253.                 break;
  1254.             default:
  1255.                 break;
  1256.             }
  1257.             break;
  1258.  
  1259.         case updateEvt:
  1260.             if (RSupdate((GrafPtr) myEvent.message))
  1261.                 if (MacRGupdate((WindowPtr) myEvent.message))
  1262.                     if (RGupdate((GrafPtr) myEvent.message) ==0) 
  1263.                         TekDisable(RGgetVG((GrafPtr) myEvent.message));
  1264.             break;
  1265.  
  1266.         case keyDown:
  1267.         case autoKey:
  1268.             doKeys();        /* All key events are processed through here */
  1269.             break;
  1270.  
  1271.         case diskEvt:            /* check to see if disk needs to be initialized */
  1272.             myEvent.where.h = 100; myEvent.where.v = 120;
  1273.             if (noErr != (( myEvent.message >> 16 ) & 0xffff )) {    /* check hi word */
  1274.                 DILoad();
  1275.                 dibadmount( &myEvent.where, myEvent.message);
  1276.                 DIUnload();
  1277.             }
  1278.             break;
  1279.  
  1280.         case activateEvt:
  1281.             if ((myEvent.modifiers & activeFlag)==1) {
  1282.                 int i;
  1283.     
  1284.                 putln("enable event");
  1285.                 AdjustMenus();
  1286.                 DrawMenuBar();
  1287.                 i=findbyWind((GrafPtr) myEvent.message);    /* We need to know who */
  1288.                 if (i>=0) {
  1289.                     if ((screens[i].curgraph>-1) && (!(myEvent.modifiers & optionKey)))
  1290.                         detachGraphics(screens[i].curgraph);
  1291.                     changeport(scrn,i);
  1292.                     scrn=i;
  1293.                     }
  1294.                 if ((i=RSfindvwind((GrafPtr) myEvent.message))>=0) {
  1295.                     if (RSTextSelected(i)) {                    /* BYU 2.4.11 */
  1296.                         EnableItem(myMenus[Fil],FLprint);        /* BYU 2.4.11 */
  1297.                         EnableItem(myMenus[Edit],EDcopy);        /* BYU 2.4.11 */
  1298.                         EnableItem(myMenus[Edit],EDcopyt);        /* BYU 2.4.11 */
  1299.                     } else {                                    /* BYU 2.4.11 */
  1300.                         DisableItem(myMenus[Fil],FLprint);        /* BYU 2.4.11 */
  1301.                         DisableItem(myMenus[Edit],EDcopy);        /* BYU 2.4.11 */
  1302.                         DisableItem(myMenus[Edit],EDcopyt);        /* BYU 2.4.11 */
  1303.                     }                                            /* BYU 2.4.11 */
  1304.                     RSactivate(i);
  1305.                     myfrontwindow=(WindowPeek) myEvent.message;
  1306.                     myfronttype=DEC_WINDOW;
  1307.                     myfrontvs = i;
  1308.                     myfrontRgn =0L;
  1309.                     updateCursor(1);
  1310.                 } else {                    
  1311.                     myfrontwindow=(WindowPeek) myEvent.message;
  1312.                     myfronttype=TEK_WINDOW;
  1313.                     myfrontRgn =0L;
  1314.                     updateCursor(1);
  1315.                     if ( (i = RGgetdnum((GrafPtr) myEvent.message)) >-1) {
  1316.                         if (( i = RGgetVS( i)) >-1) {
  1317.                             EnableItem(myMenus[Fil],FLprint);    /* BYU 2.4.11 - enable printing */
  1318.                             EnableItem(myMenus[Edit],EDcopy);    /* BYU 2.4.11 - enable copying */
  1319.                             DisableItem(myMenus[Edit],EDcopyt);    /* BYU 2.4.11 */
  1320.                             i = findbyVS( i);
  1321.                             changeport(scrn,i);
  1322.                             scrn=i;
  1323.                             }
  1324.                         }
  1325.                 }
  1326.             } else {
  1327.                 int i;
  1328.  
  1329.                 putln("disable event");
  1330.                 AdjustMenus();
  1331.                 DrawMenuBar();
  1332.                 if ((i=RSfindvwind((GrafPtr) myEvent.message))>=0)
  1333.                     RSdeactivate(i);
  1334.                         NoWindow();
  1335.                 }
  1336.             break;
  1337.         case app4Evt:
  1338.             switch(( myEvent.message >>24) &0xff) {        /* App4 is a multi-event event */
  1339.                 case switchEvt:
  1340.                     if (myEvent.message & 0x20)
  1341.                         /*Convert clipboard here if necc. (it is not)*/;
  1342.  
  1343.                     if (myEvent.message & 0x1) {        /* Resume Event */
  1344.                         GrafPtr window;
  1345. /*                        int vs;                            /* BYU 2.4.11 - defined above. */
  1346.  
  1347.                         putln("resume");
  1348.                         suspended = FALSE;                /* We are no longer in suspension */
  1349.                         DisableItem( myMenus[Edit],EDcut);
  1350.                         DisableItem( myMenus[Edit],EDundo);
  1351.                         DisableItem( myMenus[Edit],EDclear);
  1352.  
  1353.                         initKeyBoardMapping();            /* BYU 2.4.12 - keyboard changed? */
  1354.  
  1355.                         if (theWorld.systemVersion < 0x0700)    /* BYU 2.4.18 */
  1356.                             optionKeys();                        /* BYU 2.4.18 */
  1357.  
  1358.                         window = FrontWindow();            /* Who's on first */
  1359.                         if ( (vs=RSfindvwind(window)) >= 0) {
  1360.                             RSactivate(vs);
  1361.                             myfrontwindow = (WindowPeek) window;
  1362.                             myfronttype=DEC_WINDOW;
  1363.                             myfrontvs = vs;
  1364.                             myfrontRgn =0L;
  1365.                             updateCursor(1);
  1366.                         } else if ( (long)window != 0L) {
  1367.                             myEvent.message = (long) window;
  1368.                             myEvent.modifiers |= activeFlag;
  1369.                             myEvent.what = activateEvt;
  1370.                             myEvent.when = TickCount();
  1371.                             SystemEvent( &myEvent);
  1372.                             }
  1373.                         }
  1374.                     else {                                /* Suspend Event */
  1375.                         GrafPtr window;
  1376. /*                        int vs;                            /* BYU 2.4.11 - defined above. */
  1377.  
  1378.                         putln( "suspend");
  1379.                         suspended=TRUE;                    /* We be in waitin' */
  1380.                         EnableItem( myMenus[Edit],EDcut);
  1381.                         EnableItem( myMenus[Edit],EDundo);
  1382.                         EnableItem( myMenus[Edit],EDclear);
  1383.  
  1384.                         if (theWorld.systemVersion < 0x0700)    /* BYU 2.4.18 */
  1385.                             optionKeysOff();                    /* BYU 2.4.18 */
  1386.  
  1387.                         window = FrontWindow();            /* Who's on first */
  1388.                         if ((window = FrontWindow())) {
  1389.                             if ( (vs=RSfindvwind(window)) >= 0)
  1390.                                 RSdeactivate(vs);
  1391.                             else if ( (long)window != 0L) {
  1392.                                 myEvent.message = (long) window;
  1393.                                 myEvent.modifiers &= (~activeFlag);
  1394.                                 myEvent.what = activateEvt;
  1395.                                 myEvent.when = TickCount();
  1396.                                 SystemEvent( &myEvent);
  1397.                                 }
  1398.                             }
  1399.                         NoWindow();
  1400.                         }
  1401.                     break;            /* switch of myEvent.message >>24 */
  1402.                 }
  1403.             break;
  1404.         }
  1405.  
  1406.     } else if (cursorBlink && !suspended) {                /* BYU 2.4.11 */
  1407.         whichWindow = FrontWindow();                    /* BYU 2.4.11 */
  1408.         if ( (vs=RSfindvwind(whichWindow)) >= 0)        /* BYU 2.4.11 */
  1409.             if (vs == screens[scrn].vs)                    /* BYU 2.4.11 */
  1410.                 RScursblink(vs);                        /* BYU 2.4.11 */
  1411.     }                                                    /* BYU 2.4.11 */
  1412.     updateCursor(0);
  1413. }
  1414.  
  1415. void Wait4Mouse
  1416.   (
  1417.     void
  1418.   )
  1419. {
  1420.     EventRecord myEvent;
  1421.  
  1422.     while(!EventAvail(WaitEvents,&myEvent))
  1423.       {
  1424.         DoModem();                                        /* BYU 2.4.15 */
  1425.         Stask();
  1426. #if 0                                                    /* BYU 2.4.15 */
  1427.         DoNetEvents();                                    /* BYU 2.4.15 */
  1428. #endif                                                    /* BYU 2.4.15 */
  1429. #if 0                                                    /* BYU 2.4.15 */
  1430.         rftpd(0);
  1431. #endif                                                    /* BYU 2.4.15 */
  1432.       } /* while */
  1433.     FlushEvents( WaitEvents, 0 );
  1434. }
  1435.  
  1436. void WaitSeconds                                        /* BYU 2.4.15 */
  1437.   (                                                        /* BYU 2.4.15 */
  1438.     int myseconds                                        /* BYU 2.4.15 */
  1439.   )                                                        /* BYU 2.4.15 */
  1440. {                                                        /* BYU 2.4.15 */
  1441.     long mytime = TickCount() + 60 * myseconds;            /* BYU 2.4.15 */
  1442.                                                         /* BYU 2.4.15 */
  1443.     while(mytime > TickCount())                            /* BYU 2.4.15 */
  1444.       {                                                    /* BYU 2.4.15 */
  1445.         DoModem();                                        /* BYU 2.4.15 */
  1446.         Stask();                                        /* BYU 2.4.15 */
  1447.         DoNetEvents();                                    /* BYU 2.4.15 */
  1448.       } /* while */                                        /* BYU 2.4.15 */
  1449.     FlushEvents( WaitEvents, 0 );                        /* BYU 2.4.15 */
  1450. }                                                        /* BYU 2.4.15 */
  1451.  
  1452. int getmacro
  1453.   (
  1454.     int n,
  1455.     unsigned char *dest
  1456.   )
  1457. {
  1458.     unsigned char *s;
  1459.  
  1460.     if (n<0 || n>9)
  1461.         return(-1);
  1462.  
  1463.     s = macro[n];
  1464.     while (*s) {
  1465.         switch( *s) {
  1466.         case MACRO_IP :
  1467.             *dest++='\\';
  1468.             *dest++='i';
  1469.             break;
  1470.         case MACRO_LINES :
  1471.             *dest++='\\';
  1472.             *dest++='#';
  1473.             break;
  1474.         case '\\':
  1475.             *dest++='\\';
  1476.             *dest++='\\';
  1477.             break;
  1478.         case '\015':
  1479.             *dest++='\\';
  1480.             *dest++='r';
  1481.             break;
  1482.         case '\012':
  1483.             *dest++='\\';
  1484.             *dest++='n';
  1485.             break;
  1486.             
  1487. #ifdef OLD_CRAP
  1488.         case '\015':
  1489.             s++;
  1490.             if (*s == '\012' || *s=='\000') {
  1491.                 *dest++='\\';
  1492.                 *dest++='n';
  1493.                 }
  1494.             else {
  1495.                 *dest++='\\';
  1496.                 *dest++='0';
  1497.                 *dest++='1';
  1498.                 *dest++='5';
  1499.                 s--;
  1500.                 }
  1501.             break;
  1502. #endif
  1503.         case '\t':
  1504.             *dest++='\\';
  1505.             *dest++='t';
  1506.             break;
  1507.         default: 
  1508.             if ( isprint(*s)) 
  1509.                 *dest++=*s;
  1510.             else {
  1511.                 *dest++='\\';
  1512.                 *dest++= (*s / 64) +'0';
  1513.                 *dest++= ((*s % 64) / 8)+'0';
  1514.                 *dest++= (*s % 8) +'0';
  1515.                 }
  1516.             break;
  1517.             }
  1518.         s++;
  1519.         }
  1520.     *dest=0;
  1521.     return( 0);
  1522. }
  1523.